#pragma once
#include <fstream>
#include "mesh.h"
#include "sphere.h"
namespace NBE
{
	class Max12Exporter : public SceneExport
{
public:
	Max12Exporter();
	~Max12Exporter();

	/** Exports the scene. */
	int				DoExport( const TCHAR* name, ExpInterface *ei, Interface* i, BOOL suppressprompts=FALSE, DWORD options=0 );

	/** Show DLL's "About..." box */
	void			ShowAbout( HWND hwnd );

	/** Number of extensions supported */
	int				ExtCount();
	
	/** Extension #n (i.e. "3DS") */
	const TCHAR*	Ext( int n );					
	
	/** Long ASCII description (i.e. "Autodesk 3D Studio File") */
	const TCHAR*	LongDesc();
	
	/** Short ASCII description (i.e. "3D Studio") */
	const TCHAR*	ShortDesc();
	
	/** ASCII Author name */
	const TCHAR*	AuthorName();
	
	/** ASCII Copyright message */
	const TCHAR*	CopyrightMessage();
	
	/** Other message #1 */
	const TCHAR*	OtherMessage1();
	
	/** Other message #2 */
	const TCHAR*	OtherMessage2();
	
	/** Version number * 100 (i.e. v3.01 = 301) */
	unsigned int	Version();
	
	/** Returns TRUE if option supported. */
	BOOL			SupportsOptions( int ext, DWORD options );



	enum TAG
	{
		OBJECT = 0,
		PARENT,
	};

 
 

	struct MyFace
	{
		MyFace(int v0,int v1,int v2):x(v0),y(v1),z(v2)
		{}
		int x,y,z;
	};




	size_t vertexExist(Vertex& v);//return index of vertex
	
	int ExportMeshFromNode(IGameNode* node);

	int ExportMat(IGameNode* node);//export all the material in the obj, then later , only export the index of material

	void ExportObjectsFromNode(IGameNode* node);//switch case 
 
	int matExist(IGameMaterial* pMat);

	void outputFacesByMesh(IGameNode* node);
	
	void outputMaterialInfo(IGameMaterial* mat);

	INT64 getObjectByName(const char* objName);

	INT64 addStringToData(char* str);

	int getMaterialIndexing(IGameMaterial* mat);

private:
	IGameScene*		m_igame;
	FILE*			m_fh;
	std::ofstream		m_ofs;
	void			deinit();

	Max12Exporter( const Max12Exporter& );
	Max12Exporter& operator=( const Max12Exporter& );
 
	//for get data
	std::vector<IGameMaterial*> matVec;
	std::vector<Object*> objectVec;
	std::vector<Vertex> vertexVec;
	std::vector<unsigned int> indexVec;

	//for write into file
	std::vector<unsigned char> MeshData;
	std::vector<unsigned char> MaterialData;
	std::vector<unsigned char> ObjectData;
	std::vector<unsigned char> VertexData;
	std::vector<unsigned char> IndexData;

	std::vector<unsigned char> BatchData;
	std::vector<unsigned char> texMapData;
	std::vector<unsigned char> stringData;//all the names
	std::vector<unsigned char> textureData;

};
	




}